//
//  EPMMainTabBarController.m
//  WeiBoByOC
//
//  Created by 马继鵬 on 17/3/19.
//  Copyright © 2017年 7TH. All rights reserved.
//

#import "EPMMainTabBarController.h"
#import "EPMBaseNavController.h"
#import "EPMtabBar.h"
#import "EPMComposeView.h"
@interface EPMMainTabBarController ()

@end

@implementation EPMMainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self addChildControllers];
    
    //自定义tabbar
    EPMtabBar* epmTabBar = [[EPMtabBar alloc]init];
    
    [self setValue:epmTabBar forKey:@"tabBar"];
    
    //点击事件回调
    epmTabBar.btnClickkBlock = ^{
        EPMComposeView* composeView = [EPMComposeView new];
        [composeView showComposeViewwithTarget:self];
    };
    
}

- (void)addChildControllers{
    [self addControllerWithCls:@"EPMHomeViewController" title:@"首页" image:@"tabbar_home"];
    [self addControllerWithCls:@"EPMMessageViewController" title:@"消息" image:@"tabbar_message_center"];
    [self addControllerWithCls:@"EPMDiscoverViewController" title:@"发现" image:@"tabbar_discover"];
    [self addControllerWithCls:@"EPMProfileViewController" title:@"我" image:@"tabbar_profile"];
    
    
}

- (void)addControllerWithCls: (NSString*)clsName title:(NSString*)title image:(NSString*)imageName{
    
    Class clz = NSClassFromString(clsName);
    UIViewController* controller = [clz new];
    
    controller.navigationItem.title = title;
    controller.tabBarItem.title = title;
    //生成图片并渲染
    UIImage* normalImage = [UIImage imageNamed:imageName];
    normalImage = [normalImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIImage* selImage = [UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",imageName]];
    selImage = [selImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    //设置图片
    controller.tabBarItem.image = normalImage;
    controller.tabBarItem.selectedImage = selImage;
    //设置文字颜色NSForegroundColorAttributeName
    [controller.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState:UIControlStateSelected];
    EPMBaseNavController* nav = [[EPMBaseNavController alloc]initWithRootViewController:controller];
    [self addChildViewController:nav];
}


@end
